<template>
  <div>
    <!--条件筛选-->
    <TopFilter :list="topFilterList" :cols="4" labelWidth="85" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!--操作 -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <!-- 列筛选-->
    <FilterTable
      ref="table"
      columnsRef="partInventoryManagerPartUpdateSPPIndex"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :onRowSelectChange="handleRowSelectChange"
      :datakey="'rows'"
      :isSelectColumn="false"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls">
        <el-button size="small" type="primary" @click="handleUpload">上传</el-button>
        <el-button size="small" type="primary" @click="visible1 = true">库存明细</el-button>
      </template>
    </FilterTable>

    <!--对话框-->
    <BaseDialog :visible.sync="visible1" title="库存明细" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <StoreDetail :type="handleType" :rowData="formData" />
    </BaseDialog>
  </div>
</template>

<script>
import { messageAction } from '@/utils';
import { dictionary } from '@/utils/dictMixin';
import { authority } from '@/utils/authMixin';
import { getPartUploadSPPDatas, PartUploadSPP } from '@/api/part/inventoryManager/partUpdateSPP';
import StoreDetail from './storeDetail';

// // // import res from '@/mock/tableData';
// 维护工具主文件
export default {
  name: 'zxWhMainPage',
  components: {
    StoreDetail
  },
  mixins: [dictionary],
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      fetchParams: {},
      dialogTitle: '',
      selectedList: [], // 选中的列表
      fetchApi: getPartUploadSPPDatas,
      visible1: false,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {}
    };
  },
  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'PART_NO',
          placeholder: '配件代码'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '配件代码',
          dataIndex: 'partNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件名称',
          dataIndex: 'partName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '有效库存',
          dataIndex: 'stockQuantity',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    handleRowSelectChange(e) {
      this.selectedList = e;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    closeHandler(val, type) {
      // 关闭
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    // 点击上传
    async handleUpload() {
      let res = await PartUploadSPP();
      if (res.resultCode == 200) {
        messageAction('上传成功', 'success');
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
